// index.js
// 获取应用实例
const app = getApp()
Page({
  data: {
    theme:getApp().globalData.presentTheme.midColor.match(/wux-(\S*)/)[1],
    themeName:getApp().globalData.presentTheme.deepColor.match(/wux-(\S*)/)[1],
    current: 0,
    last: 0,
    path:[
      '/pages/home/home','-----请 忽 略 此 问 题-----','/pages/shop/shop','/pages/person/person'
    ],
    bgImg:'',
    visible1: false,
    landscape:{
      in:false,//in：当前是播放
      enter:true,
      // exit:false,//禁止退出动画
      exit:true,//允许退出动画
      animationClassName:'wux-animate--fadeInDown'
    }
  },
  onChange(e) {
    // console.log('onChange', e.detail)
    const that=this;
    if(e.detail.key!==1){//非扫一扫
      var pageUrl=that.data.path[e.detail.key]
      wx.switchTab({url:pageUrl})
    }
    else{//扫一扫
    }
  },
  onOpen1() {
    this.setData({
      ['landscape.in']:true,//播放
      current: 1,
      visible1: true,
      theme:getApp().globalData.presentTheme.midColor.match(/wux-(\S*)/)[1],
      themeName:getApp().globalData.presentTheme.deepColor.match(/wux-(\S*)/)[1],
    })
  },
  chooseScan(){
    this.setData({last:this.data.current})
    this.onOpen1();
    //console.log('-----可以忽略此问题-----');
  },
  onClose1() {
    const that=this;
    this.setData({
      current: that.data.last,
      visible1: false,
      ['landscape.in']:false,//退出
    })
  },
  async navToCamera(e){
    console.log(e.target.dataset['way'])
    var choice=e.target.dataset['way'];
    // await this.onClose1()//隐藏压屏窗
    if(choice==='takePhoto'){
      //调用相机拍照
      //跳转到拍摄页面
      await wx.navigateTo({
        url: '/pages/takePhoto/takePhoto',
      })
    }
    else if(choice==='chooseGallery'){
      //从相册选择
      wx.chooseImage({
        count: 1,
        sizeType: ['original'],
        sourceType: ['album'],
        success (res) {
          // tempFilePath可以作为img标签的src属性显示图片
          const tempFilePaths = res.tempFilePaths
          console.log(tempFilePaths[0]);
          var tmpPath=tempFilePaths[0];
          wx.navigateTo({
            url: '/pages/takePhoto/scanning/scanning',
            success: function(res) {
              // 通过eventChannel向被打开页面传送数据
              res.eventChannel.emit('acceptDataFromOpenerPage', { imagePath: tmpPath })
            }
          })
        }
      })
    }
  },
  doNotMove(){
    return;
  }
})
